<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Log;
use app\api\model\wanlshop\Sms;
/**
 * 手机短信接口
 */
class Newsms extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function sendPostRequest($data){
        $curl = curl_init('http://message.106ad.cn/sms.aspx');
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, [
            'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
        ]);
        $response = curl_exec($curl);
        if (curl_errno($curl)) {
            echo 'Curl error: ' . curl_error($curl);
        }
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        $xml = simplexml_load_string($response);
        $result = [
            'message'=>$xml->message,
            'returnstatus'=>$xml->returnstatus,
            'remainpoint'=>$xml->remainpoint,
            'taskID'=>$xml->taskID,
            'successCounts'=>$xml->successCounts
        ];
        return $result;

    }
    //发送短信
    public function send($param){
        extract($param);
        $data = [
            'userid'=>'157',
            'account'=>'dinghaoxian',
            'password'=>'dinghaoxian',
            'mobile'=>$mobile,
            'content'=>$sign,
            'sendTime'=>'',
            'action'=>'send',
            'extno'=>'',
        ];
        $res = $this->sendPostRequest($data);

        return $res;
    }
}

